/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.chart.survey;

import java.awt.Color;

import twaver.Element;
import twaver.Node;
import twaver.TWaverConst;
import twaver.chart.PercentChart;

public class ConjunctionChart extends PercentChart{
	
	public ConjunctionChart(){
		this.setTitle("Using Ajax in conjunction with:");
		this.setBackground(SurveyDemo.background);
		this.setGradient(true);
		this.setPercentLabelCenter(true);
		this.setEnableYZoom(false);
		this.setEnableYTranslate(false);
		this.setBackgroundVisible(true);
		this.setBackgroundOutlineColor(Color.WHITE);
		this.setBackgroundFillColor(Color.GREEN);
		this.setBackgroundGradientFactory(TWaverConst.GRADIENT_EXTEND_DIAGONAL);
		
		addElement("ColdFusion", 280);
		addElement("Java", 723);
		addElement(".NET", 381);
		addElement("PHP", 1218);
		addElement("Perl", 119);
		addElement("Python", 315);
		addElement("Ruby on Rails",	257);
		addElement("LAMP",	494);
		addElement("Other",	238);
	}
	
	private void addElement(String name, int responseCount){
		Element element = new Node();
		element.setName(name);
		element.putChartValue(responseCount);
		element.putChartMax(2618);
		element.putChartColor(SurveyDemo.color);
		element.putClientProperty("ResponseCount", responseCount);
		element.putChartPercentStyle(TWaverConst.PERCENT_STYLE_PLANE);
		this.box.addElement(element);
	}
	
	public String getPercentLabel(Element element){
		int value = (int)element.getChartValue();
		String percent = TWaverConst.DEFAULT_DOUBLE_FORMATER.format(value/2618.0*100);

		return "<html>" + element.getName() + " <font color=red>" + percent + 
			"%</font> <font color=blue>" + value + "</font></html>";
	}
	

}